/*
 *  Me.js
 *  created by qinghong
 *  2016-7-11
 */

import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Navigator,
    ListView
} from 'react-native';

import NavBar from '../../Common/NavBar';
import MeCell from './MeCell';
import Constants from '../../Common/Constants';

export default class Me extends Component {

    constructor(props) {
        super(props);
        var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        // 初始状态
        this.state = {
            dataSource: ds.cloneWithRows(this.getRowsData())
        };
        // 必须绑定，否则onPress报错
        this.renderRow = this.renderRow.bind(this);
    }

    getRowsData():Array {
        return [
            {id: 0, icon: require('../../images/icon.png'),    text: '阿狸'},
            {id: 1, icon: require('../../images/setting.png'), text: '设置'},
            {id: 2, icon: require('../../images/about.png'),   text: '关于'}
        ];
    }

    selectCell(meData:Object) {
        alert('进入 -> ' + meData.id);

        {/*
         const { navigator } = this.props;
         if (navigator) {
         navigator.push({
         name: 'JobDetail',
         component: JobDetail,
         params: {
         jobData: jobData
         }
         });
         }
         */
        }
    }

    renderRow(meData:Object) {
        return <MeCell onSelect={() => this.selectCell(meData)} meData={meData}/>;
    }

    render() {
        var MeListView = <ListView
            automaticallyAdjustContentInsets={false}
            dataSource={this.state.dataSource}
            renderRow={this.renderRow}
            style={{height: Constants.window.screenHeight-Constants.window.navHeight-Constants.window.tabHeight}}/>;
        return (
            <View style={{justifyContent: 'center', alignItems: 'center'}}>
                <NavBar titleIcon={require('../../images/navLogo.png')}/>
                {MeListView}
            </View>
        );
    }
}

